package com.sx.manage.controller.company;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sx.manage.controller.base.MBaseController;
import com.sx.manage.service.company.MCompanyInfoTempWebServiceImpl;
import com.sx.manage.servlet.ViewAndModel;
import com.sx.model.manage.mybatis.form.company.MCompanyInfoTempForm;
import com.sx.model.manage.mybatis.vo.company.MCompanyInfoTempVO;
import com.sx.model.manage.mybatis.vo.result.ResultBooleanVO;
import com.sx.model.manage.mybatis.vo.result.ResultListVO;
import com.sx.model.manage.mybatis.vo.result.ResultObjectVO;

/**
 * 公司用户录入公司信息
 * 
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/company_temp")
public class MCompanyInfoTempController extends MBaseController {
	/*** 日志 */
	private Logger log = LoggerFactory.getLogger(this.getClass());
	// 公司临时信息 webService
	@Resource(name = "companyInfoTempWebServiceImpl")
	private MCompanyInfoTempWebServiceImpl companyInfoTempWebServiceImpl;


	public MCompanyInfoTempWebServiceImpl getCompanyInfoTempWebServiceImpl() {
		return companyInfoTempWebServiceImpl;
	}

	public void setCompanyInfoTempWebServiceImpl(MCompanyInfoTempWebServiceImpl companyInfoTempWebServiceImpl) {
		this.companyInfoTempWebServiceImpl = companyInfoTempWebServiceImpl;
	}

	/** 数据列表列表 */
	@RequestMapping(value = "list_view")
	public ViewAndModel list_view(MCompanyInfoTempForm form) {
		log.info("公司收集信息数据列表界面form={}",form);
		ViewAndModel modelView = new ViewAndModel(request, cache);
		modelView.setViewName("company/temp/company_list");
		return modelView;
	}

	/** 添加界面跳转 */
	@RequestMapping(value = "view_add")
	public ViewAndModel view_add(MCompanyInfoTempForm form) {
		log.info("公司收集信息添加界面form={}",form);
		ViewAndModel modelView = new ViewAndModel(request, cache);
		modelView.setViewName("company/temp/company_edit");
		return modelView;
	}

	/** 编辑界面跳转 */
	@RequestMapping(value = "view_edit/{id}")
	public ViewAndModel view_edit(@PathVariable Long id) {
		log.info("公司收集信息编辑界面id={}",id);
		ViewAndModel modelView = new ViewAndModel(request, cache);
		modelView.setViewName("company/temp/company_edit");
		ResultObjectVO<MCompanyInfoTempVO> result = companyInfoTempWebServiceImpl.queryById(id);
		modelView.addObject("mCompanyVO", result.getObjVo());
		return modelView;
	}

	/** 详情界面跳转 */
	@RequestMapping(value = "view_detail/{id}")
	public ViewAndModel view_detail(@PathVariable Long id) {
		log.info("公司收集信息详情界面id={}",id);
		ViewAndModel modelView = new ViewAndModel(request, cache);
		modelView.setViewName("company/temp/company_detail");
		ResultObjectVO<MCompanyInfoTempVO> result = companyInfoTempWebServiceImpl.queryById(id);
		modelView.addObject("mCompanyVO", result.getObjVo());
		return modelView;
	}

	/** 编辑数据保存 */
	@RequestMapping(value = "update")
	@ResponseBody
	public ResultBooleanVO save(MCompanyInfoTempForm form, BindingResult errors) {
		log.info("公司收集信息更新数据form={}",form);
		String error = this.fieldValidate(form, errors);
		if (null != error) {
			return new ResultBooleanVO(false, null, error);
		}
		return companyInfoTempWebServiceImpl.update(form, loginConsumer());
	}

	/** 翻页信息获取 */
	@RequestMapping(value = "page")
	@ResponseBody
	public ResultListVO<MCompanyInfoTempVO> page(MCompanyInfoTempForm form) {
		log.info("公司收集信息列表数据界面form={}",form);
		return companyInfoTempWebServiceImpl.queryPage(form);
	}

	@RequestMapping(value = "pass/{id}")
	@ResponseBody
	public ResultBooleanVO pass(Long id) {
		log.info("公司收集信息通过id={}");
		return companyInfoTempWebServiceImpl.pass(id, loginConsumer());
	}

} // end class